import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import HomePageView from '../views/home/HomePageView.vue'
import DurationAvg from "@/views/DurationAvg.vue";
import WarningSum from "@/views/WarningSum.vue";
import DisposeWarning from "@/views/DisposeWarning.vue";
import UserSum from "@/views/UserSum.vue";


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      requiresAuth: true
    },
  },
  {
    path: '/userSum',
    name: 'userSum',
    component: UserSum,
    meta: {
      requiresAuth: true
    },
  },
  {
    path: '/warningSum',
    name: 'warningSum',
    component: WarningSum,
    meta: {
      requiresAuth: true
    },
  },
  {
    path: '/disposeWarning',
    name: 'disposeWarning',
    component: DisposeWarning,
    meta: {
      requiresAuth: true
    },
  },
  {
    path: '/durationAvg',
    name: 'durationAvg',
    component: DurationAvg,
    meta: {
      requiresAuth: true
    },
  },
  {
    path: '/homePage',
    name: 'homePage',
    redirect: '/homePage/warningManagement',
    component: HomePageView,
    meta: {
      requiresAuth: true
    },
    children: [
      // {
      //   path: '/homePage/businessManagement',
      //   name: 'businessManagement',
      //   component: () => import(/* webpackChunkName: "BusinessManagement" */ '../views/home/BusinessManagement.vue')
      // },
      {
        path: '/homePage/pdManagement',
        name: 'pdManagement',
        component: () => import(/* webpackChunkName: "PersonnelDatabaseManagement" */ '../views/home/PersonnelDatabaseManagement.vue')
      },
      {
        path: '/homePage/warningManagement',
        name: 'warnManagement',
        component: () => import(/* webpackChunkName: "PersonnelDatabaseManagement" */ '../views/home/WarningManagement.vue')
      },
      {
        path: '/homePage/cameraManagement',
        name: 'cameraManagement',
        component: () => import(/* webpackChunkName: "PersonnelDatabaseManagement" */ '../views/home/CameraManagement.vue')
      },
      {
        path: '/homePage/userRegister',
        name: 'userRegister',
        component: () => import(/* webpackChunkName: "PersonnelDatabaseManagement" */ '../views/home/UserRegister.vue')
      },
      {
        path: '/homePage/alarmLevel',
        name: 'alarmLevel',
        component: () => import(/* webpackChunkName: "AlarmLevel" */ '../views/home/AlarmLevel.vue')
      },

      {
        path: '/homePage/userManagement',
        name: 'userManagement',
        component: () => import(/* webpackChunkName: "UserManagement" */ '../views/home/UserManagement.vue'),
      },
      {
        path: '/homePage/organizationalManagement',
        name: 'organizationalManagement',
        component: () => import(/* webpackChunkName: "OrganizationalManagement" */ '../views/home/OrganizationalManagement.vue'),
      },
      {
        path: '/homePage/rightsManagement',
        name: 'rightsManagement',
        // redirect: '/functionRole',
        component: () => import(/* webpackChunkName: "RightsManagement" */ '../views/home/RightsManagement.vue'),
      }
    ],
  },

  {
    path: '/login',
    name: 'login',
    meta: {
      requiresAuth: false // 添加requiresAuth字段来表示需要登录验证
    },
    component: () => import(/* webpackChunkName: "Warning" */ '../views/home/LoginView.vue')
  },


  {
    path: '/warning',
    name: 'warning',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "Warning" */ '../views/WarningView.vue')
  },
  {
    path: '/once',
    name: 'once',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "MostOnce" */ '../views/MostOnceView.vue')
  },
  {
    path: '/frequencyCount',
    name: 'frequencyCount',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "MostOnce" */ '../views/FrequencyCount.vue')
  },
  {
    path: '/timeLimt',
    name: 'timeLimt',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "TimeLimit" */ '../views/TimeLimitView.vue'),
  },

  {
    path: '/timeFrequency',
    name: 'timeFrequency',
    component: () => import(/* webpackChunkName: "TimeFrequency" */ '../views/TimeFrequency.vue')
  },

  {
    path: '/traffic',
    name: 'traffic',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "Traffic" */ '../views/TrafficView.vue')
  },
  {
    path: '/personnel',
    name: 'personnel',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "PersonnelIdentification" */ '../views/PersonnelIdentification.vue')
  },
  {
    path: '/user',
    name: 'user',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "UserPortrait" */ '../views/UserPortrait.vue')
  },
  {
    path: '/rule',
    name: 'rule',
    meta: {
      requiresAuth: true
    },
    component: () => import(/* webpackChunkName: "RuleView" */ '../views/RuleView.vue')
  },
  {
    path: '/bannerShow',
    name: 'bannerShow',
    meta: {
      requiresAuth: false
    },
    component: () => import(/* webpackChunkName: "bannerShow" */ '../views/bannerShow/bannerShow.vue')
  },
]

const router = new VueRouter({
  routes
})

export default router
